package ClientLibrary.UI;

import ClientLibrary.Network.NetLayer;
import CommonLibrary.Commnads.AuthorizeRequest;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.*;

public class RegistrationForm {
	
	private JFrame regFrame = new JFrame("Registration");
	private Container regCont = regFrame.getContentPane();
    private NetLayer netLayer;
    Frame frm;

    private static RegistrationForm currentForm;

    public static RegistrationForm getCurrentForm()
    {
        return currentForm;
    }

    public RegistrationForm()
    {
        currentForm = this;
    }

    TextField lLogin = new TextField(20);
    TextField lPassword=new TextField(20);
	
	public void paintFrame() {
        frm=new Frame("DataEntry frame");
        //Label lbl = new Label("Please fill this blank:");
        //frm.add(lbl);
        frm.setSize(350,200);
        frm.setVisible(true);
        frm.addWindowListener(new WindowAdapter(){
            public void windowClosing(WindowEvent e){
                System.exit(0);
            }
        });
        Panel p = new Panel();
        Panel p1 = new Panel();
        Label jLogin = new Label("Login");

        Label jPassword =new Label("Password");

        p.setLayout(new GridLayout(3,1));
        p.add(jLogin);
        p.add(lLogin);
        p.add(jPassword);
        p.add(lPassword);
        Button Submit=new Button("Login");
        Submit.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                AuthorizeRequest authRequest = new AuthorizeRequest();
                authRequest.setLogin(lLogin.getText());
                try
                {
                    netLayer.sendCommand(authRequest);
                }
                catch (Exception error)
                {
                    // TODO
                }
            }
        });
        p.add(Submit);
        p1.add(p);
        frm.add(p1,BorderLayout.NORTH);

    }

    public void setNetLayer(NetLayer netLayer){
        this.netLayer = netLayer;
    }

    public void close()
    {
        this.frm.setVisible(false);
    }
}
